<?php

class ProductController extends Controller
{
	public $layout='column1';
	public function actionIndex(){
		$model = Products::model()->findAll();
		$this->pageTitle     = 'Sản phẩm';
		$criteria            = new CDbCriteria();
		$criteria->condition = 't.del_flg!="1" AND t.show !="1"';
		$criteria->order     = 'id DESC';
		$count = Products::model()->count($criteria);
		$pages = new CPagination($count);
		//results per page
		$pages->pageSize = 16;
		$pages->applyLimit($criteria);
		$items = Products::model()->findAll($criteria);
		$this->render('index', array(
				'model'		=>	$model,
				'pages'    	=> 	$pages,
				'items'		=>	$items
		));
	}
	
	public function actionList($id)
	{
		$pro_type            = ProductsType::model()->findByPk($id);
		//$this->pageTitle     = $pro_type->type_name;
		$criteria            = new CDbCriteria();
		$criteria->condition = 't.del_flg!="1" AND t.show !="1" AND p_type_id=' . $pro_type->id;
		$criteria->order     = 'id DESC';
	
		$count = Products::model()->count($criteria);
		$pages = new CPagination($count);
		//results per page
		$pages->pageSize = 16;
		$pages->applyLimit($criteria);
		$items = Products::model()->findAll($criteria);
	
		$this->render('list', array(
				'items'    => $items,
				'pages'    => $pages,
				'pro_type' => $pro_type
		));
	}
	public function actionDetail($id) {
		$model               = Products::model()->findByPk($id);
		$this->pageTitle     = $model->p_name;
		$criteria            = new CDbCriteria();
		$criteria->condition = 't.del_flg!=1 AND t.show !="1" AND p_type_id=' . $model->p_type_id;
		$criteria->limit     = 8;
		$this->render('details', array(
				'model' => $model,
		));
	}
}